package com.orange.controller;

import com.orange.commons.Result;
import com.orange.service.MailService;
import com.orange.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Emp
 * @projectName: springboot
 * @package: com.orange.controller
 * @className: MailController
 * @description: TODO
 * @date: 2021/12/7 12:45
 * @version: 1.0
 */
@RestController
@RequestMapping("mail")
public class MailController {

    public static final String ADMIN_EMAIL="matjd0138@qq.com";

    @Resource
    private MailService mailService;

    @Resource
    private UserService userService;

    @RequestMapping("sendMail.do")
    public Result sendMail(String title, String text, List<Integer> id){
        try {
            List<String> emails = userService.queryEmail(id);
            for (String email : emails) {
                mailService.sendMail(ADMIN_EMAIL,title,text,email);
            }
            return Result.USER_OPT_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.USER_OPT_ERROR;
        }
    }
}
